package com.woniuxy.impl;

import com.sun.media.jfxmediaimpl.MediaDisposer;
import org.springframework.beans.BeansException;
import org.springframework.beans.factory.*;
import org.springframework.beans.factory.config.BeanPostProcessor;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;

import javax.security.auth.Destroyable;


public class Bean implements  BeanNameAware,
        BeanFactoryAware, ApplicationContextAware,
        BeanPostProcessor,InitializingBean, DisposableBean {

    public Bean() {
        System.out.println("第一步：开始创建bean对象了！");
        System.out.println("第二步：设置属性值！");
    }

    @Override
    public void setBeanName(String s) {
        System.out.println("第三步，BeanNameAware方法，设置Bean的名称"+s);
    }

    @Override
    public void setBeanFactory(BeanFactory beanFactory) throws BeansException {
        System.out.println("第四步，BeanFactoryAware，设置Bean工厂"+beanFactory);
    }

    @Override
    public void setApplicationContext(ApplicationContext applicationContext) throws BeansException {
        System.out.println("第五步，ApplicationContextAware，设置ApplicationContext的属性"+applicationContext);
    }

    @Override
    public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("第六步，BeanNameAware方法，设置Bean的名称");
        return bean;
    }

    @Override
    public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
        System.out.println("第六步半，BeanNameAware方法，设置Bean的名称");
        return bean;
    }

    @Override
    public void afterPropertiesSet() throws Exception {
        System.out.println("第七步，InitializingBean，初始化属性后");
    }

    @Override
    public void destroy() throws Exception {
        System.out.println("第八步，Disposable，销毁后");
    }
}